package com.sicheng.lc.周赛.分类.模拟;


/**
 * @author zsc
 * @version 1.0
 * @date 2022/7/7 11:51
 */
public class 向字符串添加空格 {
    //https://leetcode.cn/problems/adding-spaces-to-a-string/
    public String addSpaces(String s, int[] spaces) {
        StringBuilder builder = new StringBuilder(s.length() + spaces.length);
        int index = 0;
        for (int i = 0; i < s.length(); i++) {
            if (index < spaces.length && i == spaces[index]) {
                builder.append(' ');
                index++;
            }
            builder.append(s.charAt(i));
        }
        return builder.toString();
    }
}
